package com.cybertron.lockdown.spider.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by xiezhouyan on 15-1-20.
 */
public class PropertiesUtil {

    private static final Properties PROPERTIES;

    static {
        PROPERTIES = getProperties();
    }

    private static Properties getProperties() {
        Properties config = new Properties();
        try {
            InputStream ins = PropertiesUtil.class.getResourceAsStream("/config.properties");
            if (ins == null) {
                throw new NullPointerException("load config.properties failed!");
            }
            config.load(ins);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return config;
    }

    public static String get(String key) {
        return PROPERTIES.getProperty(key);
    }

    public static Integer getInt(String key) {
        return Integer.parseInt(PROPERTIES.getProperty(key));
    }
}
